<?php
require_once 'application/library/controller/gcLBasicAction.php';
require_once 'application/library/exception/gcExceptionDealer.php';
require_once 'application/modules/order/constant/order_constant_constant.php';
require_once 'application/modules/order/constant/order_constant_templatName.php';
require_once 'application/modules/order/services/order_services_orderEditService.php';

/**
 * 订单编辑Controller
 * @author    Soochow University
 * @version   1.0
 * @exclude   作  成  日：2011/04/07
 */
class order_orderEditController extends gcLBasicAction {

    private $objService;

    private $arrMessages = array();
    /**
    * 新规画面初期化
    * @throws gcException
    */
    public function indexAction(){
         $this->initMenu("3");
        $this->boolUserTypeCheck("2");
        $msgId = array(
            "ERR-100002");
        $this->setMessageForJs($msgId);
        $this->pvSetPageInfo();
        $arrSession = sessionHelper::getPageData(order_constant_constant::ORDER_EDIT);

        if (empty($arrParameter)) {
            $arrParameter = array();
            $arrParameter["curPage"] = 1;
            $arrParameter["pageSize"] = 10;
        }

        $this->objService= new order_services_orderEditService();
        $this->gcView->intSum = $this->objService->pbGetSupplierSum();

        $intCount = $this->objService->pbGetSupplierDataCount($arrParameter);
        $objPager=$this->pagerInit($intCount, $arrParameter["curPage"], $arrParameter["pageSize"], pageSizeGroup::PAGE_SIZE_TEN, display::SHOW);
        $arrParameter["limit"] = $objPager->getLimit();
        $arrParameter["offset"] = $objPager->getOffset();

        $arrSearchData = $this->objService->pbGetSupplierData($arrParameter,$arrSession);


        $this->gcView->arrSearchData=$arrSearchData;
        $this->gcView->arrSupplierInfo = $arrSession["SupplierInfo"];
        $this->gcView->strGoodsCode    = $arrSession["GoodsInfo"]["GoodsCode"];
        $this->gcView->addEditFg     = $this->getParam("addEditFg");

        
        $this->gcView->render(order_constant_templatName::ORDER_EDIT);
    }
    
    /**
    * 编辑画面初期化
    * @throws gcException
    */
    public function editAction(){
         $this->initMenu("3");
        $this->boolUserTypeCheck("2");
        $msgId = array(
            "ERR-100002");
        $this->setMessageForJs($msgId);
        $this->pvSetPageInfo();
        $arrSession = sessionHelper::getPageData(order_constant_constant::ORDER_EDIT);

        if (empty($arrParameter)) {
            $arrParameter = array();
            $arrParameter["curPage"] = 1;
            $arrParameter["pageSize"] = 10;
        }

        $this->objService= new order_services_orderEditService();
        $this->gcView->intSum = $this->objService->pbGetSupplierSum();

        $intCount = $this->objService->pbGetSupplierDataCount($arrParameter);
        $objPager=$this->pagerInit($intCount, $arrParameter["curPage"], $arrParameter["pageSize"], pageSizeGroup::PAGE_SIZE_TEN, display::SHOW);
        $arrParameter["limit"] = $objPager->getLimit();
        $arrParameter["offset"] = $objPager->getOffset();

        $arrSearchData = $this->objService->pbGetSupplierData($arrParameter,$arrSession);


        $this->gcView->arrSearchData=$arrSearchData;
        $this->gcView->arrSupplierInfo = $arrSession["SupplierInfo"];
        $this->gcView->strGoodsCode    = $arrSession["GoodsInfo"]["GoodsCode"];
        $this->gcView->addEditFg     = $this->getParam("addEditFg");

        
        $this->gcView->render(order_constant_templatName::ORDER_EDIT);
    }
    
    /**
     * searchAction
     */
    public function searchAction(){
        if($this->getRequest()->isXmlHttpRequest()){
            $strFlag = $this->getParam("Flag");
            if ($strFlag == "1") {
                $arrParameter = array();
                $arrParameter["pageSize"] = $this->getParam("pageSize");
                $arrParameter["SupplierId"] = $this->getParam("SupplierId");
                $arrParameter["SupplierName"] = $this->getParam("SupplierName");
                $arrParameter["ProvCode"] = $this->getParam("ProvCode");
                sessionHelper::setPageData(order_constant_constant::ORDER_EDIT, $arrParameter);
            } else {
                $arrParameter = sessionHelper::getPageData(order_constant_constant::ORDER_EDIT);
                $arrParameter["pageSize"] = $this->getParam("pageSize");
                $arrParameter["orderColumn"] = $this->getParam("orderColumn");
                $arrParameter["order"] = $this->getParam("order");
                sessionHelper::setPageData(order_constant_constant::ORDER_EDIT, $arrParameter);
            }
            $this->objService=new order_services_orderEditService();
            $intCount = $this->objService->pbGetSupplierDataCount($arrParameter);

            $objPager=$this->getPagerParam($intCount);
            $arrParameter["limit"] = $objPager->getLimit();
            $arrParameter["offset"] = $objPager->getOffset();
            $arrSession = sessionHelper::getPageData(order_constant_constant::ORDER_EDIT);
            $arrSearchData = $this->objService->pbGetSupplierData($arrParameter,$arrSession);
            $objProv = new gcProvService();
            $arrSearchData = $objProv->getProvName($arrSearchData);

            $arrOutput = array(
                "count"      => $intCount,
                "curPage"    => $objPager->getCurPage(),
                "searchData" => $arrSearchData);
            if ($strFlag == "2") {
                $arrOutput["Parameter"] = $arrParameter;
            }
            jsonHelper::outPutJson($arrOutput);
        }else{
            echo 2;
        }
    }

    public function saveAction() {
        try {
            if ($this->getRequest()->isXmlHttpRequest()) {
                $arrSupplierName = $this->getParam("SupplierName",true);
                $arrSupplierNo   = $this->getParam("SupplierNo",true);
                foreach($arrSupplierNo as $key => $value) {
                    $arrSupplierInfo[$key]["SUPPLIER_NO"] = $value;
                    $arrSupplierInfo[$key]["SUPPLIER_NAME"] = $arrSupplierName[$key ];
                }
                $arrSession = sessionHelper::getPageData(order_constant_constant::ORDER_EDIT);
                $arrSession["SupplierInfo"] = $arrSupplierInfo;
                sessionHelper::setPageData(order_constant_constant::ORDER_EDIT, $arrSession);
                $output = array();
                jsonHelper::outPutJson($output);
            } else {
                gcExceptionDealer::throwAjaxException();
            }
        } catch (Exception $e) {
            gcExceptionDealer::setException($e);
        }
    }
    /**
     * pvSetPageInfo
     */
    private function pvSetPageInfo(){
        $this->gcView->title                        = $this->getLabel("order_EC0004_PageTitle");
        $this->gcView->order_EC0004_H1              = $this->getLabel("order_EC0004_H1");
        $this->gcView->order_EC0004_H2              = $this->getLabel("order_EC0004_H2");
        $this->gcView->order_EC0004_GoodsCode       = $this->getLabel("order_EC0004_GoodsCode");
        $this->gcView->order_EC0004_Operation       = $this->getLabel("order_EC0004_Operation");
        $this->gcView->order_EC0004_Delete          = $this->getLabel("order_EC0004_Delete");
        $this->gcView->order_EC0004_SupplierName    = $this->getLabel("order_EC0004_SupplierName");
        $this->gcView->order_EC0004_SupplierId      = $this->getLabel("order_EC0004_SupplierId");
        $this->gcView->order_EC0004_Price            = $this->getLabel("order_EC0004_Price");
        $this->gcView->order_EC0004_SearCondition   = $this->getLabel("order_EC0004_SearCondition");
        $this->gcView->order_EC0004_Clear           = $this->getLabel("order_EC0004_Clear");
        $this->gcView->order_EC0004_Set             = $this->getLabel("order_EC0004_Set");
        $this->gcView->order_EC0004_Back            = $this->getLabel("order_EC0004_Back");
        $this->gcView->order_EC0004_Num            = $this->getLabel("order_EC0004_Num");
        $this->gcView->order_EC0004_SupplierSearch  = $this->getLabel("order_EC0004_SupplierSearch");
        $this->gcView->order_EC0004_Select          = $this->getLabel("order_EC0004_Select");
        
    }
}